package pro.shushi.pamirs.hr.core.excel.exports;

import org.springframework.stereotype.Component;
import pro.shushi.pamirs.file.api.context.ExcelDefinitionContext;
import pro.shushi.pamirs.file.api.enmu.ExcelTemplateTypeEnum;
import pro.shushi.pamirs.file.api.extpoint.ExcelExportFetchDataExtPoint;
import pro.shushi.pamirs.file.api.extpoint.impl.ExcelExportSameQueryPageTemplate;
import pro.shushi.pamirs.file.api.model.ExcelCellDefinition;
import pro.shushi.pamirs.file.api.model.ExcelExportTask;
import pro.shushi.pamirs.file.api.model.ExcelWorkbookDefinition;
import pro.shushi.pamirs.file.api.util.ExcelHelper;
import pro.shushi.pamirs.file.api.util.ExcelTemplateInit;
import pro.shushi.pamirs.hr.api.model.eam.BsMtool;
import pro.shushi.pamirs.hr.api.model.eam.BsMtool;
import pro.shushi.pamirs.meta.annotation.ExtPoint;
import pro.shushi.pamirs.meta.annotation.fun.extern.Slf4j;

import java.util.Collections;
import java.util.List;

/**
 * 工装信息导出
 *
 * 数据导入导出参考：
 */
@Slf4j
@Component
public class BsMtoolExportTemplate extends ExcelExportSameQueryPageTemplate<BsMtool>
        implements ExcelTemplateInit, ExcelExportFetchDataExtPoint {

    public static final String TEMPLATE_NAME = "工装信息导出";

    @Override
    public List<ExcelWorkbookDefinition> generator() {
        // 定义导出模板
        return Collections.singletonList(
                ExcelHelper.fixedHeader(BsMtool.MODEL_MODEL, TEMPLATE_NAME)
                        .createBlock(TEMPLATE_NAME, BsMtool.MODEL_MODEL)
                        .setType(ExcelTemplateTypeEnum.EXPORT)
                        .addColumn("orgCode", "组织编码")
                        .addColumn("mtoolCode", "工装编码")
                        .addColumn("mtoolName", "工装名称")
                        .addColumn("mmdCode", "工装型号编码")
                        .addColumn("mfDevSn", "出厂序列号")
                        .addColumn("assetCode", "资产编码")
                        .addColumn("locStat", "位置状态")
                        .addColumn("mtoolStat", "状态")
                        .addColumn("storeCode", "仓库编码")
                        .addColumn("storelocCode", "储位编码")
                        .addColumn("scrapTime", "报废时间")
                        .addColumn("lastUkDate", "最后保养日期")
                        .addColumn("ukUsedTimes", "保养后使用次数")
                        .addColumn("totUsedTimes", "总使用次数")
                        .addColumn("devCode", "设备编码")
                        .addColumn("isSick", "带病作业")
                        .addColumn("mtoolSrcType", "来源")
                        .addColumn("isValid", "启用")
                        .addColumn("remark", "备注")
                        .build());
    }

    @Override
    @ExtPoint.Implement(expression = "context.model == \"" + BsMtool.MODEL_MODEL + "\" && context.name == \"" + TEMPLATE_NAME + "\"")
    public List<Object> fetchExportData(ExcelExportTask exportTask, ExcelDefinitionContext context) {
        List<Object> result =  super.fetchExportData(exportTask,context);
        // 对bsMtools做一些操作
        List<BsMtool> bsMtoolMds = (List<BsMtool>)result.get(0);
         for(BsMtool bsMtool:bsMtoolMds){
            // 补充自定义逻辑
        }
        return result;
    }

}
